from homeworks.HeJian.link import list
from threading import Condition
from threading import Lock
from threading import Thread
import time

lock = Lock()
cond = Condition(lock)
l = list()


def consumer(*args, **kwargs):
    print("The consumer is ready to read.")
    while True:
        cond.acquire()
        while True:
            print('开始清空数据')
            data = l.pop()
            print(data)
            time.sleep(1)
            # 开始减少数据直到清空
            if len(l) <= 0:
                cond.notify()
                print('清空完毕')
                cond.wait()

                break
        cond.release()


consume_thread = Thread(target=consumer)
consume_thread.start()

while True:
    cond.acquire()
    while True:
        data = input("添加数据")
        l.append(data)
        # 添加数据直到有五个
        if len(l) == 5:
            cond.notify()
            cond.wait()

    cond.release()
